local skel = fk.CreateSkill {
  name = "lb__qiongli",
  tags = { Skill.Switch },
  --derived_piles = "lb__zhe_nakexia",
}

Fk:loadTranslationTable {
  ["lb__qiongli"] = "穷理",
  --[":lb__qiongli"] = "<b>转换技</b>，出牌阶段，你可以横置或重置，阳：摸两张牌，然后将一张牌置于武将牌上，称为「<b>哲</b>」；阴：对自己造成1点火焰伤害，下次发动<a href=':lb__lianjin'><font color='red'>〖炼金〗</font></a>不弃置「<b>哲</b>」。",
  --9.20
  --[":lb__qiongli"] = "<b>转换技</b>，出牌阶段，你可以横置或重置，阳：摸一张牌，然后将一张牌置于武将牌上，称为「<b>哲</b>」；阴：对自己造成1点火焰伤害，下次发动<a href=':lb__lianjin'><font color='red'>〖炼金〗</font></a>改为弃置同颜色的「<b>哲</b>」。",
  --[":lb__qiongli"] = "<b>转换技</b>，出牌阶段，你可以横置或重置，阳：摸一张牌，然后将一张牌置于武将牌上，称为「<b>哲</b>」；阴：对自己造成1点火焰伤害。",
  --9.23
  --[":lb__qiongli"] = "<b>转换技</b>，出牌阶段限两次，你可以横置或重置，阳：摸两张牌，然后将一张牌置于武将牌上，称为「<b>哲</b>」；阴：对自己造成1点火焰伤害。",
  --9.24
  [":lb__qiongli"] = "<b>转换技</b>，出牌阶段，你可以横置或重置，阳：将一张牌置于武将牌上，称为「<b>哲</b>」；阴：对自己造成1点火焰伤害，本回合下次发动<a href=':lb__lianjin'><font color='red'>〖炼金〗</font></a>中的“花色”改为“颜色”。",

  [":lb__qiongli_yang"] = "<b>转换技</b>，出牌阶段，你可以横置或重置，<font color=\"#E0DB2F\">阳：将一张牌置于武将牌上，称为「<b>哲</b>」；</font>阴：对自己造成1点火焰伤害，本回合下次发动<a href=':lb__lianjin'><font color='red'>〖炼金〗</font></a>中的“花色”改为“颜色”。",
  [":lb__qiongli_yin"] = "<b>转换技</b>，出牌阶段，你可以横置或重置，阳：将一张牌置于武将牌上，称为「<b>哲</b>」；<font color=\"#E0DB2F\">阴：对自己造成1点火焰伤害，本回合下次发动<a href=':lb__lianjin'><font color='red'>〖炼金〗</font></a>中的“花色”改为“颜色”。</font>",


  --["#lb__qiongli_darw"] = "穷理：你可以%arg，摸两张牌，然后将一张牌置于武将牌上，称为「<b>哲</b>」",
  ["#lb__qiongli_darw"] = "穷理：你可以%arg，将一张牌置于武将牌上，称为「<b>哲</b>」",
  ["#lb__qiongli_damage"] = "穷理：你可以%arg，对自己造成1点火焰伤害，本回合下次发动〖炼金〗中的“花色”改为“颜色”",
  --["#lb__qiongli_damage"] = "穷理：你可以%arg，对自己造成1点火焰伤害",
  ["#lb__qiongli_choose"] = "穷理：请将一张牌加入「<b>哲</b>」",

  ["lb__zhe_nakexia"] = "哲",

  ["$lb__qiongli1"] = "等价交换？不，无中生有！",
  ["$lb__qiongli2"] = "看呐，表演开始了……",
}

skel:addEffect("active", {
  dynamic_desc = function (self, player, lang)
    return player:getSwitchSkillState(skel.name) == fk.SwitchYang and ":lb__qiongli_yang" or ":lb__qiongli_yin"
  end,
  anim_type = "switch",
  prompt = function(self, player, selected_cards, selected_targets)
    local chained = (player.chained and "un-chained" or "chained")
    return player:getSwitchSkillState(skel.name) == fk.SwitchYang
        and "#lb__qiongli_darw:::" .. chained
        or "#lb__qiongli_damage:::" .. chained
  end,
  can_use = function(self, player)
    return player.phase == Player.Play 
    --and player:usedSkillTimes(skel.name, Player.HistoryPhase) < 2
  end,
  target_filter = Util.FalseFunc,
  card_filter = function (self, player, to_select, selected, selected_targets)
    return #selected == 0 and player:getSwitchSkillState(skel.name) == fk.SwitchYang
  end,
  feasible = function (self, player, selected, selected_cards, card)
    return player:getSwitchSkillState(skel.name) == fk.SwitchYin or #selected_cards == 1
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    player:setChainState(not player.chained)
    if player:getSwitchSkillState(skel.name) == fk.SwitchYang then
      if player.dead then return end
      room:damage {
        from = player,
        to = player,
        skillName = skel.name,
        damage = 1,
        damageType = fk.FireDamage,
      }
      if player.dead then return end
      room:setPlayerMark(player, "@@lb__lianjin-turn", 1)
    else
      --[[
      if player.dead then return end
      player:drawCards(2, skel.name)
      if player.dead or player:isNude() then return end
      local ids = room:askToCards(player, {
        min_num = 1,
        max_num = 1,
        skill_name = skel.name,
        include_equip = true,
        cancelable = false,
        prompt = "#lb__qiongli_choose",
      })
      if #ids > 0 then
        player:addToPile("lb__zhe_nakexia", ids, true, skel.name, player)
      end
      --]]
      player:addToPile("lb__zhe_nakexia", effect.cards, true, skel.name, player)
    end
  end,
})

return skel